/**************************************************************************
 *   Swarm.h                                                              *
 *                                                                        *
 *   Copyright (C) 2009 Paul Tagliamonte ( paultag@ubuntu.com )           *
 *   This program is free software; you can redistribute it and/or modify *
 *   it under the terms of the GNU General Public License as published by *
 *   the Free Software Foundation; either version 1, or (at your option)  *
 *   any later version.                                                   *
 *                                                                        *
 *   This program is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of       *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
 *   GNU General Public License for more details.                         *
 *                                                                        *
 *   You should have received a copy of the GNU General Public License    *
 *   along with this program; if not, write to the Free Software          *
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *
 *                                                                        *
 **************************************************************************/

#ifndef _SWARM_H
#define _SWARM_H INC

#include "SwarmExceptions.h"
#include "Prim/node.h"

class Swarm {
	private:

	signed int x;
	signed int y;
	std::vector<node *> * NodeList;

	protected:

	void construct( signed int x, signed int y, int NodeCount ) {
		this->x = x;
		this->y = y;
		this->NodeList = new std::vector<node *>();
		for ( signed int n = 0; n < y; ++n ) {
			for ( signed int m = 0; m < x; ++m ) {
				this->NodeList->push_back( new node( NodeCount ) );
			}
		}
	}

	public:

	/*
	 * Constructor. Takes values for swarm X count, swarm Y count, and Node Value Counts.
	 * The constructor creates the swarm, and primes for action.
	 */
	Swarm ( signed int x, signed int y, int NodeCount ) {
		this->construct( x, y, NodeCount );
	}
	Swarm ( signed int x, signed int y ) {
		this->construct( x, y, 4 );
	}
	Swarm() {
		this->construct( 100, 100, 4 );
	}

	/*
	 * getNode takes two values, one for target X, and one for target Y.
	 * Returns the node pointer inside the swarm.
	 */
	node * getNode( signed int x, signed int y ) {
		node * ret;

		if ( x >= this->x || y >= this->y ) {
			SwarmOutOfRangeException e;
			throw e;
		}

		signed int index = (( y * this->y ) + x );
		ret = this->NodeList->at( index );

		return ret;
	}

	/*
	 * isComplete returns if the entire swarm is happy in it's current decision,
	 * this verifies that every node isComplete
	 */
	bool isComplete() {
		bool ret = false;

		for ( unsigned int i = 0; i < this->NodeList->size(); ++i ) {
			
		}
		return ret;
	}
};

#endif
